package com.android.love.adapter;

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.ImageView.ScaleType;

import com.android.love.R;
import com.android.love.util.ActivityUtil;
import com.android.love.util.ImageUtils;
import com.android.love.util.LogUtil;
import com.android.love.vo.Goods;
import com.android.love.vo.Meixiu;
import com.github.kevinsawicki.wishlist.ViewUtils;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.ImageLoadingListener;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.assist.SimpleImageLoadingListener;
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;

public class MeixiuAdapter extends BaseAdapter {
	private static final String TAG = "CommentAdapter";
	private ImageLoader loader;
	private List<Meixiu> meixius = Collections.emptyList();;
	private Context context;

	public MeixiuAdapter(Context context, ImageLoader loader,
			List<Meixiu> meixius) {
		super();
		this.context = context;
		this.loader = loader;
		this.meixius = meixius;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return meixius.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return meixius.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			convertView = View.inflate(context, R.layout.meixiu_item, null);
			holder = new ViewHolder();
			holder.iv_meixiu_img = (ImageView) convertView
					.findViewById(R.id.iv_meixiu_img);
			holder.iv_meixiu_vip = (ImageView) convertView
					.findViewById(R.id.iv_meixiu_vip);
			holder.tv_meixiu_look = (TextView) convertView
					.findViewById(R.id.tv_meixiu_look);
			holder.tv_meixiu_price = (TextView) convertView
					.findViewById(R.id.tv_meixiu_price);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		// Goods good = new Goods();
		Meixiu meixiu = meixius.get(position);
		holder.tv_meixiu_look.setText(meixiu.getViewer_count() + "人已看过");
		if (meixiu.getPrice() == 0) {
			holder.tv_meixiu_price.setText("免费");
			ViewUtils.setGone(holder.iv_meixiu_vip, true);
		} else {
			ViewUtils.setGone(holder.iv_meixiu_vip, false);
			holder.tv_meixiu_price.setText("￥" + meixiu.getPrice());
		}
		loader.displayImageForSize(meixiu.getImage(), holder.iv_meixiu_img,
				ImageUtils.getOptions(R.drawable.zw1), new SimpleImageLoadingListener(), 0, 0, 0, 0, 0, 0, 2f,true);
		return convertView;
	}

	public static class ViewHolder {
		ImageView iv_meixiu_img;
		ImageView iv_meixiu_vip;
		TextView tv_meixiu_look;
		TextView tv_meixiu_price;
	}

}
